<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单车列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>单车名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>存放位置：</label>
                                <input type="text" name="location"/>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="type">
                                    <option value="">所有</option>
                                    <option value="1">普通</option>
                                    <option value="2">电车</option>
                                </select>
                            </li>
                            <li>
                                <label>出租状态：</label>
                                <select name="rentStatus">
                                    <option value="">所有</option>
                                    <option value="1">未出租</option>
                                    <option value="2">已出租</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="admin:bicycle:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="admin:bicycle:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="admin:bicycle:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="admin:bicycle:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('admin:bicycle:edit')}]];
        var removeFlag = [[${@permission.hasPermi('admin:bicycle:remove')}]];
        var prefix = ctx + "admin/bicycle";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "单车",
                detailView: true,
                detailFormatter: detailFormatter,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'bikId',
                    title: '单车唯一标识',
                    visible: false
                },
                {
                    field: 'name',
                    title: '单车名称',
                    formatter: function(value, row, index) {
                        return '<strong>'+ row.name +'</strong>';
                    }
                },
                    {
                        field: 'type',
                        title: '类型',
                        formatter: function (value, row, index) {
                            if (row.type == 1) {
                                return '<strong>普通</strong>';
                            } else if (row.type == 2){
                                return '<strong>电车</strong>';
                            }
                        },
                        cellStyle: function (value, row, index) {
                            if (row.type == 1) {
                                return {
                                    css: {
                                        'color': '#f88513'
                                    }
                                };
                            } else if (row.type == 2) {
                                return {
                                    css: {
                                        'color': '#6f05b6'
                                    }
                                };
                            }
                        }
                    },
                {
                    field: 'price',
                    title: '价格',
                    formatter: function(value, row, index) {
                        if(row.price!=null){
                            var actions = [];
                            actions.push('￥'+row.price+' /小时');
                            return actions.join('');
                        }
                    }
                },

                {
                    field: 'location',
                    title: '存放位置'
                },
                {
                    field: 'rentStatus',
                    title: '出租状态',
                    formatter: function (value, row, index) {
                        if (row.rentStatus == 1) {
                            return '<strong>未出租</strong>';
                        } else if (row.rentStatus == 2) {
                            return '<strong>已出租</strong>';
                        }
                    },
                    cellStyle: function (value, row, index) {
                        if (row.rentStatus == 1) {
                            return {
                                css: {
                                    'color': '#037203'
                                }
                            };
                        } else if (row.rentStatus == 2) {
                            return {
                                css: {
                                    'color': '#cb1711'
                                }
                            };
                        }
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.bikId + '\')"><i class="fa fa-edit"></i></a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.bikId + '\')"><i class="fa fa-remove"></i></a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="selectImage(\'' + row.bikId + '\')"><i class="fa fa-image "></i></a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        //单车信息详情
        function detailFormatter(index, row) {
            let html = [];
            html.push('<p><b>车辆简介: </b> '+ row.introduce);
            html.push('<p><b>更新时间: </b> '+ row.updateDate);
            return html.join('');
        }

        /* 单车状态显示 */
        function statusTools(row) {
            if (row.status == 2) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.bikId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.bikId + '\')"></i> ';
            }
        }

        /* 单车管理-停用 */
        function disable(bikId) {
            $.modal.confirm("确认要停用车辆吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "bikId": bikId, "status": 2 });
            })
        }

        /* 单车管理-启用 */
        function enable(bikId) {
            $.modal.confirm("确认要启用车辆吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "bikId": bikId, "status": 1 });
            })
        }

        /* 单车管理-选择图片 */
        function selectImage(houseId) {
            var url = prefix + '/selectImage/' + houseId;
            $.modal.openTab("选择图片", url);
        }
    </script>
</body>
</html>